package com.hongye.backstage.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.hongye.backstage.dao.HongyeIssueTypeDao;
import com.hongye.backstage.entity.HongyeIssueTypeEntity;
import com.hongye.backstage.service.HongyeIssueTypeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fyd
 * @email 2104371759@qq.com
 * @date 2022/4/20
 * @time 9:34
 */
@Service
public class HongyeIssueTypeServiceImpl implements HongyeIssueTypeService {

    @Autowired(required = false)
    private HongyeIssueTypeDao hongyeIssueTypeDao;

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 获取所有发布类型
     * @return
     */
    @Override
    public List<HongyeIssueTypeEntity> getIssueTypeListAll() {
        String str = redisTemplate.opsForValue().get("IssueTypeList");
        if (StringUtils.isNotEmpty(str)){
            List<HongyeIssueTypeEntity> typeList = JSON.parseObject(str, new TypeReference<List<HongyeIssueTypeEntity>>() {
            });
            return typeList;
        }else {
            List<HongyeIssueTypeEntity> issueTypeListAll = hongyeIssueTypeDao.getIssueTypeListAll();
            String jsonString = JSON.toJSONString(issueTypeListAll);
            redisTemplate.opsForValue().set("IssueTypeList",jsonString);
            return issueTypeListAll;
        }



    }
}
